package exam.zte.S1;

import java.util.*;

public class Main {

    public static int p, q;
    public static Integer[] reports;
    public static int[] order;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        p = sc.nextInt();
        q = sc.nextInt();
        reports = new Integer[p];
        order = new int[1001];
        for (int i = 0; i < p; i++) {
            reports[i] = sc.nextInt();
        }
        Arrays.fill(order, -1);
        for (int i = 0; i < q; i++) {
            int a = sc.nextInt();
            order[a] = i + 1;
        }
        solution();
    }

    private static void solution() {
        Arrays.sort(reports, (a, b) -> {
            if (a.equals(b))
                return -1;
            if (order[a] + order[b] < 0)
                return a - b;
            if (order[a] * order[b] < 0)
                return order[b] - order[a];
            return order[a] - order[b];
        });
        for (int i = 0; i < reports.length; i++) {
            if (i > 0)
                System.out.print(" ");
            System.out.print(reports[i]);
        }
        System.out.println();
    }
}
